Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for -force-color to the CLI. #10975

Merged
merged 3 commits into from
Oct 6, 2021
Merged

Conversation

apollo13
Copy link
Contributor

This should fix #10973

@apollo13
Copy link
Contributor Author

@jrasell Would appreciate a review. I have verified manually and it works, not to sure about tests. On the other hand I couldn't really find any for -no-color either :D

@apollo13
Copy link
Contributor Author

I am pretty sure that the CSI snapshot failures in the test are not my fault! ;)

@apollo13
Copy link
Contributor Author

I does not yet seem to work in gitlab CI, mhm :/ That will be fun to figure out.

@apollo13
Copy link
Contributor Author

Okay, so -force-color does work, but the env variable does not. This seems to be caused by the fact that plan calls Meta.Colorize() which only takes flags into account but not the matching env variables. I am not 100% sure how nomad maps env vars to flags, any pointers?

@apollo13
Copy link
Contributor Author

apollo13 commented Aug 3, 2021

Okay, so -force-color does work, but the env variable does not. This seems to be caused by the fact that plan calls Meta.Colorize() which only takes flags into account but not the matching env variables. I am not 100% sure how nomad maps env vars to flags, any pointers?

Fixed for this PR, should be ready for review now

@jrasell jrasell self-assigned this Sep 6, 2021
@jrasell jrasell self-requested a review September 6, 2021 12:20
command/meta.go Outdated Show resolved Hide resolved
jrasell
jrasell previously requested changes Sep 7, 2021
Copy link
Member

@jrasell jrasell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for this @apollo13 and sorry for the delay in reviewing. I have an line comment which I would appreciate your thoughts on.

Another comment which appears a couple of times would be to remove the (CI systems mainly) statement in the help outputs. I'd prefer the user to understand why they need to use the flag, rather than read the help and maybe assume they can override because of the CI detail. Again I am open to opinions here.

@apollo13
Copy link
Contributor Author

I have fixed up the flag defaults and it should work as expected now. If there are performance issues we have to reevaluate.

@apollo13 apollo13 requested a review from jrasell September 10, 2021 09:04
@apollo13
Copy link
Contributor Author

@lgfa29 I have rebased this PR onto the latest no-color changes in main. While on it I have simplified the code because Colorize doesn't need to check for a terminal since meta.Ui is only set when a terminal exists: https://github.com/hashicorp/nomad/blob/main/main.go#L118 (this is checked in main.go). Given that main.go already parses -no-color itself and puts it into the env there is also no reason to check the no-color flag (which now makes the test fail due to the way they are written :/).

I like how my PR looks now because it only bothers about the flags and env variables in one place. Sadly this "one place" is main.go which probably makes this somewhat annoying to test. I do not really have an idea on how to fix this -- I am open for ideas :) I guess we could somewhat "fix" this by moving the creation of meta.Ui into an utility function that could be tested more easily.

@apollo13
Copy link
Contributor Author

I have pushed a new commit with a setupUi utility function, cleaned up the code and fixed the tests. Let me know what you think.

@apollo13
Copy link
Contributor Author

@lgfa29 Any chance you could review this PR? :)

@lgfa29 lgfa29 added this to the 1.2.0 milestone Oct 2, 2021
@lgfa29
Copy link
Contributor

lgfa29 commented Oct 2, 2021

@lgfa29 Any chance you could review this PR? :)

Will do it in the coming days 🙂
Sorry of the delay here.

Copy link
Contributor

@lgfa29 lgfa29 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for this great PR @apollo13!

It's great to see this logic being pulled out of main.go since it's now easier to test it 🙂

I pushed a commit to change the logic slightly so that -no-color takes precedence of -force-color. These two options are meant to be used together, but in case they are it would be better to avoid colors since it's a safer option.

What do you think?

@lgfa29 lgfa29 dismissed jrasell’s stale review October 5, 2021 19:01

Code has beed refatored.

@apollo13
Copy link
Contributor Author

apollo13 commented Oct 6, 2021

Personally I think that force is stronger than no so I would have expected force to win, but no strong feelings…

@lgfa29
Copy link
Contributor

lgfa29 commented Oct 6, 2021

Personally I think that force is stronger than no so I would have expected force to win, but no strong feelings…

So now we need a -force-no-color to beat them all 😅

Just kidding, or course. The reasoning behind -no-color to win is that using the two flags at the same time is most likely a mistake, and -no-color is the safest option since it won't pollute the output in case colors are not supported.

I will merge this now then. Thank you for the contribution!

@lgfa29 lgfa29 merged commit 6cb3697 into hashicorp:main Oct 6, 2021
@github-actions
Copy link

I'm going to lock this pull request because it has been closed for 120 days ⏳. This helps our maintainers find and focus on the active contributions.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 14, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Command line flag to force color during CI runs
4 participants